-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add assertion if nullptr is passed to parse function #3593
Conversation
A |
It seems I cannot suppress the issue in the test suite, but I need to add the attribute to the input adapter's constructor. Which makes no sense, because we added the attribute exactly to help the compiler/sanitizer find such an issue. I am not sure how to continue:
I currently tend more to adding an assertion and making the documentation more clear that passing a null pointer yields undefined behavior. Alternatively, we could make the behavior more similar to the Both alternatives also have the advantage that the constructor remains What do you think? |
I agree that keeping exceptions out of constructors is a good idea. I'd still prefer a way to differentiate parse errors from invalid input adapters. This goes beyond the scope of this PR but is what I've been asking for from the start. To that end, an alternative might be to add For |
Yes, this is also a pain point for me, because there are issues again and again where people seem to not understand that "unexpected end of file" at position 0 means that a file could not be opened in the first place.
Sounds good. But for this PR, should we go for the behavior that a null pointer yields EOF? Edit: We can also not test that behavior, because again we cannot pass a null pointer to the input adapter without being punished by UBSAN... This is how CLion tells me that the parameter cannot be null: I get the feeling that an assertion and updated documentation is the best we can do without investing too much for this edge case. I like the idea of adding some kind of |
I guess we assert in the constructor for easy diagnosis in the cases where assert is enabled, and add the nullptr check in |
And we can remove the |
Co-authored-by: Florian Albrechtskirchinger <[email protected]>
Addresses #3584 by adding an assertion and documenting the preconditions.